<?php

namespace App\Http\Requests;
/**
 * 群发消息表单验证
 * @package App\Http\Requests
 */
class AdminWxMassPost extends AdminBaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'title' => 'required',
            'filter_rule.type' => 'required|in:all,tagid,openids,area,file',
            'filter_rule.tagid' => 'required_if:massData.filter_rule.type,tagid',
            'filter_rule.openids' => 'required_if:massData.filter_rule.type,openids',
            'filter_rule.country' => 'required_if:massData.filter_rule.type,area',
            'filter_rule.fileurl' => 'required_if:massData.filter_rule.type,file',
            //'is_open' => 'in:0,1',
            'push_time' => 'nullable|date',
            'msg_type' => 'required|in:text,news,image,video,voice,card',
            'content' => 'required_if:msg_type,text',
            'material.material_id' => 'required_if:msg_type,news,image,video,voice',
            'card_id' => 'required_if:msg_type,card',
        ];
    }

    /**
     * 定义错误消息
     * @return array
     */
    public function messages()
    {
        return [
            'title.required' => '请输入群发的标题',
            'filter_rule.type.required' => '请选择正确的群发筛选方式',
            'filter_rule.type.in' => '请选择正确的群发筛选方式',
            'filter_rule.tagid.required_if' => '请选择标签ID',
            'filter_rule.openids.required_if' => '请指定用户openid列表',
            'filter_rule.openids.min' => '至少提供两个用户openId',
            'filter_rule.country.required_if' => '请选择群发国家',
            'filter_rule.fileurl.required_if' => '请上传带有用户openId的excel文件',
            //'is_open.in' => '请选择是否开启群发',
            'push_time.date' => '请选择正确的推送时间',
            'msg_type.required' => '请选择群发消息类型',
            'msg_type.in' => '请选择正确的群发消息类型',
            'content.required_if' => '请输入群发内容',
            'material.material_id.required_if' => '请选择有效的素材',
            'card_id.required_if' => '请输入卡券ID',
        ];
    }
}
